define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'keesuishoupai/order/index' + location.search,
                    table: 'keesuishoupai_order',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order Sn'), operate: 'LIKE'},
                        {field: 'good_title', title: __('Good Title'), operate: 'LIKE'},
                        {field: 'good_image', title: __('Good Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'good_score', title: __('Good Score')},
                        {field: 'number', title: __('Number')},
                        {field: 'score', title: __('Score')},
                        {field: 'receive_name', title: __('Receive Name')},
                        {field: 'receive_mobile', title: __('Receive Mobile')},
                        {field: 'receive_address', title: __('Receive Address')},
                        {field: 'receive_note', title: __('Receive Note')},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'buttons', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:[{
                            name: 'detail',
                            text: __('查看'),
                            title: __('查看操作'),
                            classname: 'btn btn-xs btn-info btn-dialog',
                            url: 'keesuishoupai/order/show',
                            icon:"fa fa-eye",
                            callback: function (data) {
                            },
                            visible: function (row) {
                                    return true;
                            }
                        },{
                            name: 'deliver',
                            text: __('发货'),
                            title: __('发货处理'),
                            classname: 'btn btn-xs btn-warning btn-dialog',
                            url:"keesuishoupai/order/deliver",
                            extend:'data-area=\'["500px","360px"]\'',
                            visible: function (row) {
                                if(row.status === 1){
                                    return true;
                                }
                            }
                        }], formatter: Table.api.formatter.operate},
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        deliver:function(){
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});